package com.mcflies.commons.util;

import java.io.File;

import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

/**
 * 
 * XMLParseUtil.java
 * 
 * @describe：XML解析工具类
 * @Copyright(c) 2012-2024 Study,mcfly
 * @author mcfly_jun
 */
public class XMLParseUtil {
	private static Logger log = Logger.getLogger(XMLParseUtil.class);

	/**
	 * @describe:获取xml根元素
	 * 
	 * @param xmlFilePath
	 * @return
	 */
	public static Element getRootElement(String xmlFilePath) {
		Element rootElement = null;
		try {
			Document document = getXMLDocument(xmlFilePath);
			rootElement = document.getRootElement();
		} catch (Exception e) {
			log.error("XMLParseUtil类解析xml出现异常：：" + e.getMessage());
		}
		return rootElement;
	}

	/**
	 * @describe:获取xml的DOM
	 * @param xmlFilePath
	 * @return
	 * @throws Exception
	 */
	private static Document getXMLDocument(String xmlFilePath) throws Exception {
		SAXReader reader = new SAXReader();
		Document document = reader.read(new File(xmlFilePath));
		return document;
	}
}
